+01: from cython.parallel import prange
__pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+02: import numpy as np
__pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
03: cimport cython
04:
05: @cython.boundscheck(False)
06: @cython.wraparound(False)
07: @cython.cdivision(True)
+08: def mandelbrot_cy(complex centre, float view_side, int n_max_iter = 255, int view_side_pixels = 500):
/* Python wrapper */
static PyObject *__pyx_pw_46_cython_magic_295e0d013b998d73940e6698bcdfbd69_1mandelbrot_cy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_46_cython_magic_295e0d013b998d73940e6698bcdfbd69_1mandelbrot_cy = {"mandelbrot_cy", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_46_cython_magic_295e0d013b998d73940e6698bcdfbd69_1mandelbrot_cy, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_46_cython_magic_295e0d013b998d73940e6698bcdfbd69_1mandelbrot_cy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
__pyx_t_double_complex __pyx_v_centre;
float __pyx_v_view_side;
int __pyx_v_n_max_iter;
int __pyx_v_view_side_pixels;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("mandelbrot_cy (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_centre,&__pyx_n_s_view_side,&__pyx_n_s_n_max_iter,&__pyx_n_s_view_side_pixels,0};
PyObject* values[4] = {0,0,0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_centre)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_view_side)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("mandelbrot_cy", 0, 2, 4, 1); __PYX_ERR(0, 8, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n_max_iter);
if (value) { values[2] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 3:
if (kw_args > 0) {
PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_view_side_pixels);
if (value) { values[3] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mandelbrot_cy") < 0)) __PYX_ERR(0, 8, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_centre = __Pyx_PyComplex_As___pyx_t_double_complex(values[0]); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
__pyx_v_view_side = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_view_side == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
if (values[2]) {
__pyx_v_n_max_iter = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_n_max_iter == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
} else {
__pyx_v_n_max_iter = ((int)0xFF);
}
if (values[3]) {
__pyx_v_view_side_pixels = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_view_side_pixels == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L3_error)
} else {
__pyx_v_view_side_pixels = ((int)0x1F4);
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("mandelbrot_cy", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 8, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("_cython_magic_295e0d013b998d73940e6698bcdfbd69.mandelbrot_cy", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_46_cython_magic_295e0d013b998d73940e6698bcdfbd69_mandelbrot_cy(__pyx_self, __pyx_v_centre, __pyx_v_view_side, __pyx_v_n_max_iter, __pyx_v_view_side_pixels);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_46_cython_magic_295e0d013b998d73940e6698bcdfbd69_mandelbrot_cy(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_double_complex __pyx_v_centre, float __pyx_v_view_side, int __pyx_v_n_max_iter, int __pyx_v_view_side_pixels) {
PyObject *__pyx_v_step = NULL;
float __pyx_v_step_memview;
int __pyx_v_i;
int __pyx_v_j;
int __pyx_v_n;
__pyx_t_double_complex __pyx_v_c;
__pyx_t_double_complex __pyx_v_z;
float __pyx_v_cons_x;
float __pyx_v_cons_y;
PyObject *__pyx_v_ret = NULL;
__Pyx_memviewslice __pyx_v_ret_memview = { 0, 0, { 0 }, { 0 }, { 0 } };
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("mandelbrot_cy", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
__Pyx_AddTraceback("_cython_magic_295e0d013b998d73940e6698bcdfbd69.mandelbrot_cy", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_step);
__Pyx_XDECREF(__pyx_v_ret);
__PYX_XDEC_MEMVIEW(&__pyx_v_ret_memview, 1);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_tuple__19 = PyTuple_Pack(15, __pyx_n_s_centre, __pyx_n_s_view_side, __pyx_n_s_n_max_iter, __pyx_n_s_view_side_pixels, __pyx_n_s_step, __pyx_n_s_step_memview, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_n, __pyx_n_s_c, __pyx_n_s_z, __pyx_n_s_cons_x, __pyx_n_s_cons_y, __pyx_n_s_ret, __pyx_n_s_ret_memview); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__19);
__Pyx_GIVEREF(__pyx_tuple__19);
/* … */
__pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_46_cython_magic_295e0d013b998d73940e6698bcdfbd69_1mandelbrot_cy, NULL, __pyx_n_s_cython_magic_295e0d013b998d7394); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_mandelbrot_cy, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(4, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_root_cache_ipython_cython__cyth, __pyx_n_s_mandelbrot_cy, 8, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 8, __pyx_L1_error)
+09: step = view_side/view_side_pixels
__pyx_t_1 = PyFloat_FromDouble((__pyx_v_view_side / ((float)__pyx_v_view_side_pixels))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_step = __pyx_t_1;
__pyx_t_1 = 0;
+10: cdef float step_memview = step
__pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_v_step); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 10, __pyx_L1_error)
__pyx_v_step_memview = __pyx_t_2;
11:
12: cdef int i, j, n
13: cdef double complex c
14: cdef double complex z
+15: cdef float cons_x = centre.real - view_side*.5
__pyx_v_cons_x = (__Pyx_CREAL(__pyx_v_centre) - (__pyx_v_view_side * .5));
+16: cdef float cons_y = centre.imag + view_side*.5
__pyx_v_cons_y = (__Pyx_CIMAG(__pyx_v_centre) + (__pyx_v_view_side * .5));
17: #cdef complex cons = centre + view_side*complex(-.5, .5)
18:
+19: ret = np.zeros((view_side_pixels, view_side_pixels))
__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_view_side_pixels); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_view_side_pixels); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
__pyx_t_3 = 0;
__pyx_t_5 = 0;
__pyx_t_5 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
if (likely(__pyx_t_5)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_4, function);
}
}
__pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6);
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_v_ret = __pyx_t_1;
__pyx_t_1 = 0;
+20: cdef double[:, :] ret_memview = ret
__pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_ret, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 20, __pyx_L1_error)
__pyx_v_ret_memview = __pyx_t_7;
__pyx_t_7.memview = NULL;
__pyx_t_7.data = NULL;
21:
+22: for i in range(view_side_pixels):
__pyx_t_8 = __pyx_v_view_side_pixels;
__pyx_t_9 = __pyx_t_8;
for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
__pyx_v_i = __pyx_t_10;
+23: for j in range(view_side_pixels):
__pyx_t_11 = __pyx_v_view_side_pixels;
__pyx_t_12 = __pyx_t_11;
for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
__pyx_v_j = __pyx_t_13;
+24: c = cons_x + j * step_memview + (cons_y - i * step_memview)*1j
__pyx_v_c = __Pyx_c_sum_double(__pyx_t_double_complex_from_parts((__pyx_v_cons_x + (__pyx_v_j * __pyx_v_step_memview)), 0), __Pyx_c_prod_double(__pyx_t_double_complex_from_parts((__pyx_v_cons_y - (__pyx_v_i * __pyx_v_step_memview)), 0), __pyx_t_double_complex_from_parts(0, 1.0)));
+25: z = 0 + 0*1j
__pyx_v_z = __Pyx_c_sum_double(__pyx_t_double_complex_from_parts(0, 0), __Pyx_c_prod_double(__pyx_t_double_complex_from_parts(0, 0), __pyx_t_double_complex_from_parts(0, 1.0)));
+26: n = 0
__pyx_v_n = 0;
27: #for n in range(n_max_iter):
28: # z = z*z + c
29: # if z.real**2 + z.imag**2 > 4:
30: # ret_memview[i, j] = n
+31: while n < n_max_iter and z.real**2 + z.imag**2 <= 4:
while (1) {
__pyx_t_15 = ((__pyx_v_n < __pyx_v_n_max_iter) != 0);
if (__pyx_t_15) {
} else {
__pyx_t_14 = __pyx_t_15;
goto __pyx_L9_bool_binop_done;
}
__pyx_t_15 = (((pow(__Pyx_CREAL(__pyx_v_z), 2.0) + pow(__Pyx_CIMAG(__pyx_v_z), 2.0)) <= 4.0) != 0);
__pyx_t_14 = __pyx_t_15;
__pyx_L9_bool_binop_done:;
if (!__pyx_t_14) break;
+32: z = z*z + c
__pyx_v_z = __Pyx_c_sum_double(__Pyx_c_prod_double(__pyx_v_z, __pyx_v_z), __pyx_v_c);
+33: n += 1
__pyx_v_n = (__pyx_v_n + 1);
}
+34: if n == n_max_iter:
__pyx_t_14 = ((__pyx_v_n == __pyx_v_n_max_iter) != 0);
if (__pyx_t_14) {
/* … */
goto __pyx_L11;
}
+35: ret_memview[i, j] = 0
__pyx_t_16 = __pyx_v_i;
__pyx_t_17 = __pyx_v_j;
*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ret_memview.data + __pyx_t_16 * __pyx_v_ret_memview.strides[0]) ) + __pyx_t_17 * __pyx_v_ret_memview.strides[1]) )) = 0.0;
36: else:
+37: ret_memview[i, j] = n
/*else*/ {
__pyx_t_18 = __pyx_v_i;
__pyx_t_19 = __pyx_v_j;
*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ret_memview.data + __pyx_t_18 * __pyx_v_ret_memview.strides[0]) ) + __pyx_t_19 * __pyx_v_ret_memview.strides[1]) )) = __pyx_v_n;
}
__pyx_L11:;
}
}
+38: return ret
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_v_ret);
__pyx_r = __pyx_v_ret;
goto __pyx_L0;